import request from '@/utils/request'
import type { PaginatedResult, PaginationQuery } from '@/types/common'
import type {
  Classroom,
  ClassroomPayload,
  Course,
  CoursePayload,
  AcademicYear,
  AcademicYearPayload,
  ClassItem,
  ClassPayload,
  ClassStudent,
  ClassStudentPayload
} from '@/types/academic'

export type { AcademicYear, ClassItem, ClassPayload }

export const getClassroomList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<Classroom>>('/api/v1/classrooms/list', { params })

export const createClassroom = (payload: ClassroomPayload) =>
  request.post<Classroom>('/api/v1/classrooms/create', payload)

export const updateClassroom = (id: number, payload: ClassroomPayload) =>
  request.put<Classroom>(`/api/v1/classrooms/${id}`, payload)

export const deleteClassroom = (id: number) =>
  request.delete(`/api/v1/classrooms/${id}`)

export const getCourseList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<Course>>('/api/v1/courses/list', { params })

export const createCourse = (payload: CoursePayload) =>
  request.post<Course>('/api/v1/courses/create', payload)

export const updateCourse = (id: number, payload: CoursePayload) =>
  request.put<Course>(`/api/v1/courses/${id}`, payload)

export const deleteCourse = (id: number) =>
  request.delete(`/api/v1/courses/${id}`)

export const getAcademicYearList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<AcademicYear>>('/api/v1/academic-years/list', {
    params
  })

export const createAcademicYear = (payload: AcademicYearPayload) =>
  request.post<AcademicYear>('/api/v1/academic-years/create', payload)

export const updateAcademicYear = (id: number, payload: AcademicYearPayload) =>
  request.put<AcademicYear>(`/api/v1/academic-years/${id}`, payload)

export const deleteAcademicYear = (id: number) =>
  request.delete(`/api/v1/academic-years/${id}`)

export const getClassList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<ClassItem>>('/api/v1/classes/list', { params })

export const createClassItem = (payload: ClassPayload) =>
  request.post<ClassItem>('/api/v1/classes/create', payload)

export const updateClassItem = (id: number, payload: ClassPayload) =>
  request.put<ClassItem>(`/api/v1/classes/${id}`, payload)

export const deleteClassItem = (id: number) =>
  request.delete(`/api/v1/classes/${id}`)

export const getClassStudentList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<ClassStudent>>('/api/v1/class-students/list', {
    params
  })

export const createClassStudent = (payload: ClassStudentPayload) =>
  request.post<ClassStudent>('/api/v1/class-students/create', payload)

export const updateClassStudent = (id: number, payload: ClassStudentPayload) =>
  request.put<ClassStudent>(`/api/v1/class-students/${id}`, payload)

export const deleteClassStudent = (id: number) =>
  request.delete(`/api/v1/class-students/${id}`)
